#pragma once

/*
it is a scene class
a program can include multiple scenes
but only one scene is active
the active scene is drawn and will response to inputs
you should inherit the class to specific scenes
and you should override the functions below
	--------------------------------------------
		left_button_down
		left_button_up
		right_button_down
		right_button_up
		mouse_move
		key_down
		key_up
	--------------------------------------------
you can also not override those functions
thus the scene will behavior by default

you must override the function below
	--------------------------------------------
		init
	--------------------------------------------
you should init controls in that function
if not, the scene will do nothing
*/

class Scene :public Graphical
{
protected:
	std::vector<Graphical *> gs;										//the graphical object should be painted
	std::vector<Control *> cs;											//the controls list

	Control * find_control(int x, int y);								//find a control pointed by (x, y)
	Control * find_focused();											//find a focused control

public:
	void add_control(Control * ctl);									//add a control to the scene

	Scene();															//contructor, initialize the scene
	virtual ~Scene() {}													//dispose resources, should be overrided

	void draw(Gdiplus::Graphics & graphics) override;					//draw the scene

	//events should not be altered by clients
	void LButtonDown(int x, int y);
	void LButtonUp(int x, int y);
	void RButtonDown(int x, int y);
	void RButtonUp(int x, int y);
	void MouseMove(int button, int x, int y);
	void KeyDown(int keycode);
	void KeyUp(int keycode);

	//events should be overrided by clients
	//virtual void left_button_down(int x, int y) {}
	//virtual void left_button_up(int x, int y) {}
	//virtual void right_button_down(int x, int y) {}
	//virtual void right_button_up(int x, int y) {}
	//virtual void mouse_move(int button, int x, int y) {}
	//virtual void key_down(int keycode) {}
	//virtual void key_up(int keycode) {}

	std::function<void(int, int)> left_button_down = [](int x, int y) {};
	std::function<void(int, int)> left_button_up = [](int x, int y) {};
	std::function<void(int, int)> right_button_down = [](int x, int y) {};
	std::function<void(int, int)> right_button_up = [](int x, int y) {};
	std::function<void(int, int, int)> mouse_move = [](int button, int x, int y) {};
	std::function<void(int)> key_down = [](int keycode) {};
	std::function<void(int)> key_up = [](int keycode) {};

	Gdiplus::Graphics * graphics;
};